package com.leather.question.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leather.common.entity.Answer;
import com.leather.question.vo.AnswerDetailQueryVo;
import com.leather.question.vo.AnswerQueryVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
*  @author kevin
*/
public interface AnswerMapper extends BaseMapper<Answer> {


    /**
     * 分页获取问题答案
     * @param questionId
     * @param pageId
     * @return
     */
    @Select("select a.*,b.img_url,b.nick_name from  answer a,user b \n" +
            "where a.user_id = b.id and a.question_id = #{questionId} order by a.id desc limit #{pageId},10")
    List<AnswerQueryVo> getByQuestionId(@Param("questionId") int questionId, @Param("pageId") int pageId);


    /**
     * 删除答案
     * @param answerId
     * @param userId
     * @return
     */

    @Delete("delete from answer where id = #{answerId} and user_id = #{userId}")
    int  deleteAnswer(@Param("answerId") int answerId, @Param("userId") int userId);


    @Update("update answer set flag = 1 where question_id = #{questionId}")
    int setFlag(@Param("questionId") int questionId);


    @Select("select a.*,b.question_title from answer a,question b where a.question_id = b.id and a.user_id = #{userId} order by a.id desc" +
            " limit #{pageId},10")
    List<AnswerDetailQueryVo> getUserAnswer(@Param("userId") int userId, @Param("pageId") int pageId);

}